Skip to content

feat: deprecate string annotations#586

Open
dlech wants to merge 5 commits intomainfrom
deprecate-string-annotations
Open

feat: deprecate string annotations#586
dlech wants to merge 5 commits intomainfrom
deprecate-string-annotations

Conversation

@dlech
Copy link
Member

@dlech dlech commented Feb 1, 2026

In #563, it became obvious that the bare string annotations are not just a problem when you want to use type hints, but also a problem with deferred evaluation of annotations in general. Python treats string literal annotations as forward references and may try to evaluate them later. This evaluation fails because the D-Bus signatures are not able to be evaluated as Python code.

Now that we have proper annotation classes for D-Bus types, we can deprecate the use of bare string annotations to encourage users to switch to the new system. This becomes more urgent now that Python 3.14 has deferred evaluation of annotations enabled by default.

We do want users to have plenty of time to migrate, so we make this deprecation period a few years long.

In #563, it became
obvious that the bare string annotations are not just a problem when
you want to use type hints, but also a problem with deferred evaluation
of annotations in general. Python treats string literal annotations as
forward references and may try to evaluate them later. This evaluation
fails because the D-Bus signatures are not able to be evaluated as
Python code.

Now that we have proper annotation classes for D-Bus types, we can
deprecate the use of bare string annotations to encourage users to
switch to the new system. This becomes more urgent now that Python 3.14
has deferred evaluation of annotations enabled by default.

We do want users to have plenty of time to migrate, so we make this
deprecation period a few years long.
@dlech dlech requested a review from bdraco February 1, 2026 21:44
@codecov
Copy link

codecov bot commented Feb 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.73%. Comparing base (5c61e6f) to head (15635c3).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #586      +/-   ##
==========================================
+ Coverage   85.66%   85.73%   +0.07%     
==========================================
  Files          29       29              
  Lines        3480     3484       +4     
  Branches      601      601              
==========================================
+ Hits         2981     2987       +6     
+ Misses        308      307       -1     
+ Partials      191      190       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 1, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing deprecate-string-annotations (15635c3) with main (5c61e6f)

Summary

✅ 6 untouched benchmarks

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Deprecates bare string D-Bus signature annotations (which break under deferred evaluation of annotations) and encourages migration to typing.Annotated / dbus_fast.annotations types, adding warnings and updating docs/tests accordingly.

Changes:

  • Emit a deprecation warning when string annotations are detected during annotation parsing.
  • Update dbus_method / dbus_property documentation to show dbus_fast.annotations usage and describe the deprecation.
  • Adjust tests to keep string-annotation coverage while asserting the new deprecation warning.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/dbus_fast/_private/util.py Adds deprecation warnings when parsing string annotations.
src/dbus_fast/service.py Updates decorator docstrings to document Annotated-based typing and the new deprecation.
docs/source/high-level-service/index.rst Updates high-level service docs to reference the new annotation approach.
tests/service/test_methods.py Adds warning assertions while retaining string-annotation coverage.
tests/client/test_methods.py Adds warning assertions while retaining string-annotation coverage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 24 to 35
def deprecated_dbus_method():
inner_wrapper = dbus_method()

def outer_wrapper(*args: Any) -> Any:
with pytest.warns(
DeprecationWarning,
match="String annotations are deprecated and support will be removed in the future. Use typing.Annotated with the appropriate annotation from dbus_fast.annotations instead.",
):
return inner_wrapper(*args)

return outer_wrapper

Copy link

Copilot AI Feb 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper is duplicated in multiple test files. Consider moving it to a shared test utility (e.g., tests/util.py) or a pytest fixture to avoid repeating the warning message and logic in multiple places.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be removed eventually and is not very big, so the duplication was intentional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments